<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Title</title>
    </head>
    <body>

        <div id="app">
            <div><input type="checkbox" v-on:click = "change" v-model="checked"> <span>全选</span></div>
            <div>
                <div v-for="i in fruit">
                    <input type="checkbox" v-model="i.checked" v-on:change="just">
                    <span> {{i.value}}</span></div>
                </div>
        </div>
        <script src="../js/vue.js"></script>
        <script>

            var app = new Vue({
                el:"#app",
                data: {
                    checked:false,
                    fruit:[
                        {value:"苹果",checked:false},
                        {value:"梨子",checked:false},
                        {value:"香蕉",checked:false},
                        {value:"榴莲",checked:false}
                    ]
                },

                methods: {
                    change(){
                        if (this.checked===false){
                            for (let i = 0; i < this.fruit.length; i++) {
                                this.fruit[i].checked = true;
                            }
                        }else {
                            for (let i = 0; i < this.fruit.length; i++) {
                                this.fruit[i].checked = false;
                            }
                        }
                    },

                    just(){
                        let flag = true;
                        for (let i = 0; i < this.fruit.length; i++) {
                            if (this.fruit[i].checked===false){
                                    flag = false
                            }
                        }
                        this.checked = flag;
                    }
                }
            })
        </script>
    </body>
</html>